home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib25 / chdir.c < prev    next >
C/C++ Source or Header  |  1991-10-19  |  924b  |  47 lines

  1. #include <errno.h>
  2. #include <osbind.h>
  3. #include <stddef.h>
  4. #include <assert.h>
  5. #include <ctype.h>
  6. #include <limits.h>
  7. #include <unistd.h>
  8. #include "lib.h"
  9.  
  10. /***************************************************************
  11. chdir: change the directory and (possibly) the drive.
  12. By ERS: it's in the public domain.
  13. ****************************************************************/
  14.  
  15. int chdir(dir)
  16. const char *dir;
  17. {
  18.     int drv, old;
  19.     int r;
  20.     char tmp[PATH_MAX];
  21.     register char *d;
  22.  
  23.     assert ((dir != NULL));
  24.  
  25.     (void)_unx2dos(dir, tmp);    /* convert Unix filename to DOS */
  26.     d = tmp;
  27.     old = Dgetdrv();
  28.     if (*d && *(d+1) == ':') {
  29.         drv = toupper(*d) - 'A';
  30.         d+=2;
  31.         (void)Dsetdrv(drv);
  32.     }
  33.     else
  34.         drv = old;
  35.  
  36.     if (!*d) {        /* empty path means root directory */
  37.         *d = '\\';
  38.         *(d+1) = '\0';
  39.     }
  40.     if ((r = Dsetpath(d)) < 0) {
  41.         (void)Dsetdrv(old);
  42.         errno = -r;
  43.         return -1;
  44.     }
  45.     return 0;
  46. }
  47.